﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef Camera_h__
#define Camera_h__

#include "../base/common.h"
#include "../base/Matrix.h"
#include "../base/Vector.h"

namespace SkyEngine2d
{
	
	//! 相机
	class Camera
	{
	public:
	
		//************************************
		// 方法名:    	CreateCamera
		// 访问权限:    public static 
		// 返回值:   	Camera *
		// 参数: 		float view_width   游戏视图的宽度
		// 参数: 		float view_hight	游戏视图的高度
		// 参数: 		float near_plane	近平面距离
		// 参数: 		float far_plane		远平面距离
		//************************************
		static Camera * CreateCamera(float view_width,float view_hight,float near_plane,float far_plane);
		// 移动相机
		void moveCarme(const Vector2 & dt);
		// 更新相机
		void updataCarme();
		//获取vp矩阵
		const Matrix4X4 & getViewProjectMat()const { return m_vpMat; }
		//获取view矩阵
		const Matrix4X4 & getViewMat()const { return m_viewMatrix; }
		//获取默认相机
		static Camera * getDefultCamera();
		//设置相机坐标
		void setPosition(float x, float y);
		//获取相机位置
		Vector2 getPostion()const;
	
	private:
		Camera();
		~Camera() = default;
		bool init(float view_width, float view_hight, float near_plane, float far_plane);
	private:
		//视图矩阵   
		Matrix4X4 m_viewMatrix;
		//投影矩阵
		Matrix4X4 m_projectionMatrix;
		//视图投影矩阵
		Matrix4X4 m_vpMat;
		//相机的焦点
		Vector2  m_focus;
		//相机中的矩阵是否被改变
		bool  m_isChangeVpMat;
		//旋转
		float	m_rotationZ;
		//位置
		float	m_positionX, m_positionY;
	};
	
}

#endif // Camera_h__
